package models

import "gorm.io/gorm"

type Product struct {
	gorm.Model
	Title  string  `gorm:"type:varchar(30)" json:"title"`
	Stock  int64   `gorm:"type:int(11)" json:"stock"`
	Price  float64 `gorm:"type:decimal(10,2)" json:"price"`
	Image  string  `gorm:"type:varchar(300)" json:"image"`
	Info   string  `gorm:"type:varchar(300)" json:"info"`
	UserId int64   `gorm:"type:int(11)" json:"userId"`
}

func (p *Product) ProductAdd(db *gorm.DB) error {
	return db.Debug().Create(p).Error
}

func (p *Product) FindProductById(db *gorm.DB, productId int64) (*Product, error) {
	err := db.Debug().Where("id=?", productId).Find(p).Error
	return p, err
}
